home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / Alpha 6.5.sit / Tcl / Modes / latexComm.tcl < prev    next >
Text File  |  1996-08-15  |  18KB  |  588 lines

  1. #############################################################################
  2. #############################################################################
  3. #
  4. # latexComm.tcl (called from latex.tcl)
  5. #
  6. #############################################################################
  7. #
  8. # Author:  Tom Scavo <trscavo@syr.edu>
  9. #
  10. #############################################################################
  11. #############################################################################
  12.  
  13. #--------------------------------------------------------------------------
  14. # TeX applications
  15. #--------------------------------------------------------------------------
  16.  
  17. # Application *names* aren't needed any more!
  18.  
  19. # OzTeX:
  20. # set texAppName(OzTeX) {*OzTeX*}
  21. set texAppSig(OzTeX) {OTEX}
  22. set texAppScripts(OzTeX) ¥
  23.     {{sendOpenEvent noReply $quotedSig $filename}}
  24. # Textures:
  25. # set texAppName(Textures) {*Textures*}
  26. set texAppSig(Textures) {*TEX}
  27. set texAppScripts(Textures) {{dosc -c $quotedSig -f $filename -r}}
  28. # CMacTeX:
  29. # set texAppName(CMacTeX) {*tex}
  30. set texAppSig(CMacTeX) {*XeT}
  31. set texAppScripts(CMacTeX) ¥
  32.     {{dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}}
  33. # DirectTeX:
  34. # set texAppName(DirectTeX) {MPW*}
  35. set texAppSig(DirectTeX) {MPS*}
  36. set texAppScripts(DirectTeX) {¥
  37.     {set script "Begin; ChangeTeXProject '$filename' -check -confirm || Exit 0; ¥
  38.                     Execute ¥"{dt_TeXProject}¥"; TeXMenu -tex -formats; ¥
  39.                   End キ Dev:Null; RunSession 1 キ Dev:Null"} ¥
  40.     {dosc -r -c $quotedSig -s $script} ¥
  41. }
  42. # DirectTeX Pro:
  43. # set texAppName(DirectTeXPro) {DirectTeX*}
  44. set texAppSig(DirectTeXPro) {TeX+}
  45. set texAppScripts(DirectTeXPro) {¥
  46.     {dosc -c $quotedSig -s ¥
  47.         "if ¥$dt_TeXFormat = ¥'¥' ¥"set dt_TeXFormat -x ¥$dt_DefaultFormat¥""} ¥
  48.     {dosc -c $quotedSig -s ¥
  49.         "ProjectMgr -t ¥$dt_TeXFormat ¥"$filename¥"; MenuCommand 1 4"} ¥
  50. }
  51.  
  52. #--------------------------------------------------------------------------
  53. # DVI viewers
  54. #--------------------------------------------------------------------------
  55.  
  56. # OzTeX:
  57. # set viewDVIAppName(OzTeX) $texAppName(OzTeX)
  58. set viewDVIAppSig(OzTeX) $texAppSig(OzTeX)
  59. set viewDVIAppScripts(OzTeX) ¥
  60.     {{sendOpenEvent noReply $quotedSig $filename}}
  61. # CMacTeX:
  62. # set viewDVIAppName(CMacTeX) dvipreview
  63. set viewDVIAppSig(CMacTeX) {PIVD}
  64. set viewDVIAppScripts(CMacTeX) ¥
  65.     {{dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}}
  66. # DirectTeX Pro:
  67. # set viewDVIAppName(DirectTeXPro) $texAppName(DirectTeXPro)
  68. set viewDVIAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  69. # set viewDVIAppScripts(DirectTeXPro) ¥
  70. #     {{dosc -c $quotedSig -s ¥
  71. #         "ProjectMgr -t LaTeX ¥"$filename¥"; SelectApp; MenuCommand 1 8"}}
  72. set viewDVIAppScripts(DirectTeXPro) ¥
  73.     {{dosc -c $quotedSig -s "ProjectMgr -t ¥$dt_TeXFormat    ¥"[lindex    [winNames -f] 0]¥"; MenuCommand 1 8"}}
  74.  
  75. #--------------------------------------------------------------------------
  76. # DVI print drivers
  77. #--------------------------------------------------------------------------
  78.  
  79. # OzTeX:
  80. # set printDVIAppName(OzTeX) $texAppName(OzTeX)
  81. set printDVIAppSig(OzTeX) $texAppSig(OzTeX)
  82. set printDVIAppScripts(OzTeX) ¥
  83.     {{dosc -c $quotedSig -k 'aevt' -e 'pdoc' -r -f $filename}}
  84. # Textures:
  85. # set printDVIAppName(Textures) $texAppName(Textures)
  86. set printDVIAppSig(Textures) $texAppSig(Textures)
  87. set printDVIAppScripts(Textures) ¥
  88.     {{dosc -c $quotedSig -k 'aevt' -e 'pdoc' -r -f $filename}}
  89. # CMacTeX:
  90. # set printDVIAppName(CMacTeX) printdvi
  91. set printDVIAppSig(CMacTeX) {CMT8}
  92. set printDVIAppScripts(CMacTeX) ¥
  93.     {{dosc -c $quotedSig -k 'aevt' -e 'pdoc' -r -f $filename}}
  94. # DirectTeX Pro:
  95. # set printDVIAppName(DirectTeXPro) $texAppName(DirectTeXPro)
  96. set printDVIAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  97. set printDVIAppScripts(DirectTeXPro) ¥
  98.     {{dosc -c $quotedSig -s ¥
  99.         "ProjectMgr -t ¥$dt_TeXFormat    ¥"[lindex    [winNames -f] 0]¥"; MenuCommand 1 9"}}
  100.  
  101. #--------------------------------------------------------------------------
  102. # DVI-to-PS filters
  103. #--------------------------------------------------------------------------
  104.  
  105. # OzTeX:
  106. # set dvipsAppName(OzTeX) OzDVIPS
  107. set dvipsAppSig(OzTeX) {OzDP}
  108. set dvipsAppScripts(OzTeX) ¥
  109.     {{sendOpenEvent noReply $quotedSig $filename}}
  110. # CMacTeX:
  111. # set dvipsAppName(CMacTeX) dvips
  112. set dvipsAppSig(CMacTeX) {CMT1}
  113. set dvipsAppScripts(CMacTeX) ¥
  114.     {{dosc -c $quotedSig -k 'aevt' -e 'odoc' -t 600 -f $filename}}
  115. # DirectTeX Pro:
  116. # set dvipsAppName(DirectTeXPro) $texAppName(DirectTeXPro)
  117. set dvipsAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  118. set dvipsAppScripts(DirectTeXPro) ¥
  119.     {{dosc -c $quotedSig -s "ProjectMgr -t ¥$dt_TeXFormat    ¥"[lindex    [winNames -f] 0]¥"; directory ¥$dt_TeXProjectDir > CurrDirectory; dvips ¥$dt_TeXProjectName"}}
  120.  
  121. #--------------------------------------------------------------------------
  122. # PS viewers
  123. #--------------------------------------------------------------------------
  124.  
  125. # Mac GhostScript Viewer:
  126. # set viewPSAppName(MacGS) {Mac GS*}
  127. set viewPSAppSig(MacGS) {gsVR}
  128. set viewPSAppScripts(MacGS) ¥
  129.     {{dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}}
  130. # CMacTeX:
  131. # set viewPSAppName(CMacTeX) viewps
  132. set viewPSAppSig(CMacTeX) {CMT5}
  133. set viewPSAppScripts(CMacTeX) ¥
  134.     {{dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}}
  135.  
  136. #--------------------------------------------------------------------------
  137. # PS print drivers
  138. #--------------------------------------------------------------------------
  139.  
  140. # CMacTeX: 
  141. # set printPSAppName(CMacTeX) printps
  142. set printPSAppSig(CMacTeX) {PSP*}
  143. set printPSAppScripts(CMacTeX) ¥
  144.     {{dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}}
  145. # DirectTeX Pro:
  146. # set printPSAppName(DirectTeXPro) $texAppName(DirectTeXPro)
  147. set printPSAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  148. # set printPSAppScripts(DirectTeXPro) ¥
  149. #     {{dosc -c $quotedSig -s "SelectApp; dvips ¥$dt_TeXProjectName; ¥
  150. #                              download ¥$dt_TeXProjectName.ps"}}
  151. set printPSAppScripts(DirectTeXPro) ¥
  152.     {{dosc -c $quotedSig -s "ProjectMgr -t ¥$dt_TeXFormat    ¥"[lindex    [winNames -f] 0]¥"; directory ¥$dt_TeXProjectDir > CurrDirectory; download ¥$dt_TeXProjectName.ps"}}
  153. # Drop・PS
  154. # set printPSAppName(DropPS) {Drop・PS}
  155. set printPSAppSig(DropPS) {D・PS}
  156. set printPSAppScripts(DropPS) ¥
  157.     {{dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}}
  158.  
  159. #--------------------------------------------------------------------------
  160. # BibTeX apps
  161. #--------------------------------------------------------------------------
  162.  
  163. # CMacTeX:
  164. # set bibtexAppName(CMacTeX) {*bibtex}
  165. set bibtexAppSig(CMacTeX) {CMTu}
  166. set bibtexAppScripts(CMacTeX) ¥
  167.     {{sendOpenEvent noReply $quotedSig $filename}}
  168. # DirectTeX Pro:
  169. # set bibtexAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  170. set bibtexAppScripts(DirectTeXPro) ¥
  171.     {{dosc -c $quotedSig -s "ProjectMgr -t ¥$dt_TeXFormat    ¥"[lindex    [winNames -f] 0]¥"; MenuCommand 1 5"}}
  172. # Vince Darley's BibTeX:
  173. # set bibtexAppName(BibTeX) {BibTeX*}
  174. set bibtexAppSig(BibTeX) {Vbib}
  175. set bibtexAppScripts(BibTeX) ¥
  176.     {{sendOpenEvent noReply $quotedSig $filename}}
  177.  
  178. #--------------------------------------------------------------------------
  179. # MakeIndex apps
  180. #--------------------------------------------------------------------------
  181.  
  182. # CMacTeX:
  183. # set makeindexAppName(CMacTeX) {[Mm]ake[Ii]ndex}
  184. set makeindexAppSig(CMacTeX) {CMTt}
  185. set makeindexAppScripts(CMacTeX) ¥
  186.     {{sendOpenEvent noReply $quotedSig $filename}}
  187. # DirectTeX Pro:
  188. # set makeindexAppName(DirectTeXPro) $texAppName(DirectTeXPro)
  189. set makeindexAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  190. # set makeindexAppScripts(DirectTeXPro) ¥
  191. #     {{dosc -c $quotedSig -s ¥
  192. #         "ProjectMgr -t LaTeX ¥"$filename¥"; SelectApp; MenuCommand 1 6"}}
  193. set makeindexAppScripts(DirectTeXPro) ¥
  194.     {{dosc -c $quotedSig -s "ProjectMgr -t ¥$dt_TeXFormat    ¥"[lindex    [winNames -f] 0]¥"; MenuCommand 1 6"}}
  195. # Rick Zaccone's MakeIndex:
  196. # set makeindexAppName(MakeIndex) {MakeIndex*}
  197. set makeindexAppSig(MakeIndex) {RZMI}
  198. set makeindexAppScripts(MakeIndex) ¥
  199.     {{sendOpenEvent noReply $quotedSig $filename}}
  200.  
  201. #--------------------------------------------------------------------------
  202. # Typeset submenu
  203. #--------------------------------------------------------------------------
  204.  
  205. proc typeset {} {
  206.     # Is there a window open?
  207.     set currentWin [lindex [winNames -f] 0]
  208.     if { $currentWin == "" } {
  209.         typesetFile ""
  210.         return
  211.     }
  212.     # Is the current window part of TeX fileset?
  213.     set fset [isWindowInFileset $currentWin "tex"]
  214.     if { $fset != "" } {
  215.         if [dirtyFileset $fset] {
  216.             switch [askyesno -c "Save current TeX fileset?"] {
  217.                 "yes" {saveEntireFileset $fset}
  218.                 "no" {
  219.                      # do nothing
  220.                 }
  221.                 "cancel" {return}
  222.             }
  223.         }
  224.         typesetFile [texFilesetBaseName $fset]
  225.         return
  226.     }
  227.     # Is the window untitled or dirty?
  228.     global PREFS
  229.     set currentDoc [file tail $currentWin]
  230.     if { [set num [winUntitled]] } {
  231.         switch [askyesno -c "Save ¥"$currentDoc¥"?"] {
  232.             "yes" {
  233.                 if {[catch {set currentWin [saveAs "Untitled$num¥.tex"]}]} then {return}
  234.             }
  235.             "no" {
  236.                 set tmpFilename "Untitled$num¥.tex"
  237.                 set text [getText 0 [maxPos]]
  238.                 if { [file exists "$PREFS:tmp"] == 0 } { mkdir "$PREFS:tmp" }
  239.                 set newDoc "$PREFS:tmp:$tmpFilename"
  240.                 writeFile $newDoc $text 1
  241.                 set currentWin $newDoc
  242.             }
  243.             "cancel" {return}
  244.         }
  245.     } elseif { [winDirty] } {
  246.         switch [askyesno -c "Save ¥"$currentDoc¥"?"] {
  247.             "yes" {save}
  248.             "no" {
  249.                 set text [getText 0 [maxPos]]
  250.                 if { [file exists "$PREFS:tmp"] == 0 } { mkdir "$PREFS:tmp" }
  251.                 set newDoc "$PREFS:tmp:temp-$currentDoc"
  252.                 writeFile $newDoc $text 1
  253.                 set currentWin $newDoc
  254.             }
  255.             "cancel" {return}
  256.         }
  257.     }
  258.     # Is the current window TeX-able?
  259.     set ext [file extension $currentWin]
  260.     if { [lsearch -exact {.tex .ltx .dtx .ins} $ext] < 0 } {
  261.         typesetFile ""
  262.         return
  263.     }
  264.     # Strip off trailing garbage (if any) and typeset:
  265.     regexp {(.*) <[0-9]+>} $currentWin dummy currentWin
  266.     typesetFile $currentWin
  267. }
  268.  
  269. proc typesetSelection {} {
  270.     global PREFS
  271.     if { [isSelection] } then { 
  272.         watchCursor
  273.         message "processing selectionノ"
  274.         set currentWin [lindex [winNames -f] 0]
  275.         # Is the current window part of TeX fileset?
  276.         set fset [isWindowInFileset $currentWin "tex"]
  277.         if { $fset == "" } {
  278.             set pos1 [getPos]
  279.             if { [isInDocument] } then {
  280.                 set pos2 [selEnd]
  281.                 if { [isInDocument] } then {
  282.                     # fall through
  283.                 } else {
  284.                     beep
  285.                     set msg "Selection not in document environment.  Continue?"
  286.                     if { [askyesno $msg] == "no" } then { return }
  287.                 }
  288.             } else {
  289.                 beep
  290.                 set msg "Selection not in document environment.  Continue?"
  291.                 if { [askyesno $msg] == "no" } then { return }
  292.                 set pos2 [selEnd]
  293.             }
  294.             set body "¥r[getText $pos1 $pos2]¥r"
  295.             set searchText [getText 0 [maxPos]]
  296.         } else {
  297.             set body "¥r[getSelect]¥r"
  298.             # Will not handle a base file that is open and dirty:
  299.             set searchText [buildFilecontents [texFilesetBaseName $fset]]
  300.         }
  301.         message "building temporary documentノ"
  302.         set pattern {(¥¥documentclass.*)¥¥begin¥{document¥}}
  303.         if { ![regexp $pattern $searchText dummy preamble] } then {
  304.             set preamble "¥¥documentclass¥{article¥}¥r"
  305.         }
  306.         set rootFile [file rootname $currentWin]
  307.         set tempFile "temp-[file tail $rootFile]"
  308.         set auxFile $rootFile.aux
  309.         if { [file exists $auxFile] } {
  310.             set latexDoc [buildFilecontents $auxFile $tempFile.aux]
  311.         } else {
  312.             set latexDoc {}
  313.         }
  314.         append latexDoc $preamble [buildEnvironment "document" "" $body "¥r"]
  315.         set currentDir [file dirname $currentWin]
  316.         set latexDoc [texResolveAll $latexDoc $currentDir]
  317.         if { [file exists "$PREFS:tmp"] == 0 } { mkdir "$PREFS:tmp" }
  318.         set newFile "$PREFS:tmp:$tempFile.tex"
  319.         writeFile $newFile $latexDoc 1
  320.         typesetFile $newFile
  321.     } else {
  322.         beep
  323.         message "no selection"
  324.     }
  325. }
  326.  
  327. proc typesetClipboard {} {
  328.     global PREFS
  329.     set body "¥r[getScrap]¥r"
  330.     set pat1 {¥¥begin¥{document¥}.*¥¥end¥{document¥}}
  331.     set pat2 {¥¥documentclass}
  332.     set preamble "¥¥documentclass¥{article¥}¥r"
  333.     # Check to see if there's a document environment:
  334.     if {![regexp $pat1 $body]} then {
  335.         append text $preamble [buildEnvironment "document" "" $body "¥r"]
  336.     } else {
  337.         # Check to see if there's a ¥documentclass command:
  338.         if {![regexp $pat2 $body]} then {
  339.             append text $preamble $body
  340.         } else {
  341.             set text $body
  342.         }
  343.     }
  344.     if { [file exists "$PREFS:tmp"] == 0 } { mkdir "$PREFS:tmp" }
  345.     set newFile "$PREFS:tmp:temp-noname¥.tex"
  346.     writeFile $newFile $text 1
  347.     set currentWin $newFile
  348.     typesetFile $currentWin
  349. }
  350.  
  351. # Typeset $filename, but perform no error-checking
  352. #
  353. proc typesetFile {filename} {
  354.     if { $filename == "" } {
  355.         set filename [getfile "Choose a file to typeset:"]
  356.     }
  357.     global TeXmodeVars
  358.     set prompt {TeX app}
  359.     set flag $TeXmodeVars(runTeXInBack)
  360.     evalTeXScript tex $prompt $filename $flag
  361. }
  362.  
  363. # Apply $op to a file with extension $ext.  (See latexMenu.tcl for
  364. # many examples.)  If 'forcecurrent == 1', use the current window 
  365. # even if it belongs to a TeX fileset.
  366. #
  367. proc doTypesetCommand {op ext {forcecurrent 0}} {
  368.     if { [set filename [findAuxiliaryFile $ext $forcecurrent]] != "" } {
  369.         if { $op == "open" } { 
  370.             edit -r -m -w $filename 
  371.         } else {
  372.             $op${ext}File $filename
  373.         }
  374.     } else {
  375.         beep
  376.         alertnote "No $ext file found!"
  377.     }
  378. }
  379.  
  380. proc viewDVIFile {filename} {
  381.     set prompt {DVI viewer}
  382.     evalTeXScript viewDVI $prompt $filename
  383. }
  384.  
  385. proc printDVIFile {filename} {
  386.     set prompt {DVI print driver}
  387.     evalTeXScript printDVI $prompt $filename
  388. }
  389.  
  390. proc dvipsDVIFile {filename} {
  391.     set prompt {DVI-to-PS filter}
  392.     evalTeXScript dvips $prompt $filename
  393. }
  394.  
  395. proc viewPSFile {filename} {
  396.     set prompt {PS viewer}
  397.     evalTeXScript viewPS $prompt $filename
  398. }
  399.  
  400. proc printPSFile {filename} {
  401.     set prompt {PS print driver}
  402.     evalTeXScript printPS $prompt $filename
  403. }
  404.  
  405. proc bibtexAUXFile {filename} {
  406.     set prompt {BibTeX app}
  407.     evalTeXScript bibtex $prompt $filename
  408. }
  409.  
  410. proc makeindexIDXFile {filename} {
  411.     set prompt {MakeIndex app}
  412.     evalTeXScript makeindex $prompt $filename
  413. }
  414.  
  415. proc evalTeXScript {op prompt filename {runAppInBackground 0}} {
  416.     global ${op}Sig ${op}AppSig ${op}AppScripts
  417.     
  418.     set supportedApps [array names ${op}AppSig]
  419.     foreach app $supportedApps { lappend sigs [set ${op}AppSig($app)] }
  420.     set longPrompt "Please locate a $prompt."
  421.     if { [catch {launchBackApplSigs $sigs ${op}Sig $longPrompt} appname] } {
  422.         error "bug in 'launchBackApplSigs'"
  423.     }
  424.     set sig [set ${op}Sig]
  425.     set quotedSig "'[string trim $sig {'}]'"
  426. #     if { $runAppInBackground == 0 } { switchTo [file tail $appname] }
  427.     if { $runAppInBackground == 0 } { switchTo $quotedSig }
  428.     foreach app $supportedApps { 
  429.         if { [set ${op}AppSig($app)] == $sig } {
  430.             foreach script [set ${op}AppScripts($app)] {
  431.                 eval $script
  432.             }
  433.             return
  434.         }
  435.     }
  436.     beep
  437.     alertnote "Sorry, no support for your $prompt."
  438.     return
  439. }
  440.  
  441. # Two bugs in 'getfile' (see "alpha.bugs58"):
  442. proc openAnyTeXFile {} {
  443.     set currentWin [lindex [winNames -f] 0]
  444.     cd [file dirname $currentWin]
  445.     set    filename [getfile ""]
  446.     if { ![string length $filename] } return
  447.     edit -r -m -w $filename
  448. }
  449.  
  450. proc removeAuxiliaryFiles {} {
  451.     set word ""
  452.     set removeSilently 0
  453.     set currentWin [lindex [winNames -f] 0]
  454.     if { $currentWin == "" } { return }
  455.     set currentDir [file dirname $currentWin]
  456.     set extensions {.ps .dvi .log .aux .bbl .idx .ind .glo .gls ¥
  457.                     .toc .lof .lot .blg .ilg}
  458.     foreach ext $extensions {
  459.         message "Checking for *$ext filesノ"
  460.         set files [glob -nocomplain "$currentDir:*$ext"]
  461.         foreach file $files {
  462.             set word " more"
  463.             if {$removeSilently} {
  464.                 if {[catch {rm "$currentDir:*$ext"}]} then {
  465.                     alertnote "not all ¥"*$ext¥" files deleted"
  466.                 }
  467.                 break
  468.             } else {
  469.                 message ""
  470.                 set filename [file tail $file]
  471.                 switch [buttonAlert "Remove ¥"$filename¥"?" "yes" "no" {rm ext} {rm all} "cancel"] {
  472.                     "yes" {
  473.                         message "Removing $filenameノ"
  474.                         if {[catch {removeFile "$currentDir:$filename"}]} then {
  475.                             alertnote "¥"$filename¥" not deleted"
  476.                         } else {
  477.                             message $filename
  478.                         }
  479.                     }
  480.                     "no" {}
  481.                     "{rm ext}" {
  482.                         if {[catch {rm "$currentDir:*$ext"}]} then {
  483.                             alertnote "not all ¥"*$ext¥" files deleted"
  484.                         }
  485.                         break
  486.                     }
  487.                     "{rm all}" {
  488.                         if {[catch {rm "$currentDir:*$ext"}]} then {
  489.                             alertnote "not all ¥"*$ext¥" files deleted"
  490.                         }
  491.                         set removeSilently 1
  492.                         break
  493.                     }
  494.                     "cancel" {return}
  495.                 }
  496.             }
  497.         }
  498.     }
  499.     message "No$word files found"
  500. }
  501.  
  502. #--------------------------------------------------------------------------
  503. # Utility procs:
  504. #--------------------------------------------------------------------------
  505.  
  506. # Find a LaTeX auxiliary file with extension $ext.  If 'forcecurrent' 
  507. # is true, search the current directory without checking for TeX filesets.
  508. #
  509. proc findAuxiliaryFile {ext {forcecurrent 0}} {
  510.     
  511.     set currentWin [lindex [winNames -f] 0]
  512.     if { $currentWin == "" } { return "" }
  513.     set currentDoc [file tail $currentWin]
  514.  
  515.     if $forcecurrent {
  516.         # pretend there are no TeX filesets:
  517.         set fset ""
  518.     } else {
  519.         set fset [isWindowInFileset $currentWin "tex"]
  520.     }
  521.     
  522.     if { $fset != "" } {
  523.         
  524.         set currentWin [texFilesetBaseName $fset]
  525.         set currentDoc [file tail $currentWin]
  526.         set currentDir [file dirname $currentWin]
  527.         set docBasename [file rootname $currentDoc]
  528.         set lowerExt [string tolower $ext]
  529.         
  530.     } else {
  531.         
  532.         # we do all this if it's not a project:
  533.         set currentDir [file dirname $currentWin]        
  534.         set docBasename [file rootname $currentDoc]
  535.         set lowerExt [string tolower $ext]
  536.         
  537.         # Is the window untitled or dirty?
  538.         global PREFS
  539.         if { [set num [winUntitled]] } {
  540.             set filename $PREFS:tmp:Untitled$num¥.$lowerExt
  541.             if { [file exists $filename] } {
  542.                 return $filename
  543.             } else {
  544.                 return ""
  545.             }
  546.         } elseif { [winDirty] } {
  547.             switch [askyesno "Window dirty---continue anyway?"] {
  548.                 "yes" {
  549.                     set filename $PREFS:tmp:temp-$currentDoc¥.$lowerExt
  550.                     if { [file exists $filename] } {
  551.                         return $filename
  552.                     } else {
  553.                         # fall through
  554.                     }
  555.                 }
  556.                 "no" {return ""}
  557.             }
  558.         }
  559.     }
  560.     
  561.     # Check the current directory:
  562.     set filename $currentDir:$docBasename¥.$lowerExt
  563.     if { [file exists $filename] } {
  564.         return $filename
  565.     } else {
  566.         return ""
  567.     }
  568. }
  569.  
  570. # If the current window is untitled, return its number (i.e., either
  571. # the number 1 or the number  n  in "Untitled <n>"); otherwise, return 0.
  572. proc winUntitled {} {
  573.     set currentWin [lindex [winNames -f] 0]
  574.     if { $currentWin == "" } { return 0 }
  575.     set currentDoc [file tail $currentWin]
  576.     if { [string match $currentWin $currentDoc] } {
  577.         if { [regexp {<(.*)>} $currentDoc dummy num] } {
  578.             return $num
  579.         } else {
  580.             return 1
  581.         }
  582.     } else {
  583.         return 0
  584.     }
  585. }
  586.  
  587.  
  588.